<%@ page import="Data.data" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@page contentType="text/html; charset=UTF-8" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <title>订单信息管理系统</title>

    <style type="text/css">



        td,th{
            text-align: center;
        }

 body {
  background-color: #f0ece9;
}

header {
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;
}
header h1 {
  color: #9a9897;
}

header hr {
  margin: 20px 20px 0;
  background-color: #bc9470;
  border: 2px solid #bc9470;
  width: 30%;
  height: 0;
}
        span
            {
                float: left;
                margin-left: 50px;
                margin-top: 50px;
                width: 220px;
                height: 480px;
                border: 3px solid #b4aea9;
            }
        a:link
            {
                color:black;
                font-size: 30px;
                font-family: Arial;
            }
        a:hover
            {
                color: red;
            }
        a
            {
                margin-left: 20px;
            }
        .first
            {
                width: 1200px;
                height: 550px;
                border: 1.5px solid #b4aea9;
                margin-left: 300px;
                margin-top: 34px;
                padding-left: 20px;
            }
  
            table {
  margin: 0 auto;
  width: 90%;
  text-align: center;
  border-spacing: 0;
}
table tbody tr:first-of-type {
  background-color: #dadee1 !important;
  height: 60px;
}
table tbody tr {
  height: 45px;
}
table tbody tr:nth-child(odd) {
  background-color: #eef1f8;
}
table tbody tr:nth-child(even) {
  background-color: #ffffff;
}
table tbody tr:not([id=thead]):hover {
  cursor: pointer;
  background-color: #e9e9e9;}

    </style>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title>订单管理系统</title>
 <script src="js/test.js" type="text/javascript" charset="utf-8"></script>
 <script type="text/javascript"  src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>  
    <script>

   function doDelete(id) {
            location.href='/delete?id='+id}

  function doModify(id) {
            location.href='/modify9.jsp?id='+id}

 function deleteAll() {
				var all = $("input:checked[name='uid']"); 
				console.log(all.length);
				if(all.length == 0) {
					alert("请选择,然后进行删除");
					return; 
				}
			if (confirm("确认要删除？")) { 
          for(var i = 0; i < all.length; i++) {
					all[i].parentNode.parentNode.remove();
				}
   }
			
			}
var isCheckAll = false;  
function swapCheck() {  
            if (isCheckAll) {  
                $("input[type='checkbox']").each(function() {  
                    this.checked = false;  
                });  
                isCheckAll = false;  
            } else {  
                $("input[type='checkbox']").each(function() {  
                    this.checked = true;  
                });  
                isCheckAll = true;  
            }  
        }  

function getRow(r){
 var i=r.parentNode.parentNode.rowIndex; 
 return i ;
}
function delRow(r){ 
  
   if (confirm("确认要删除？")) { 
    document.getElementById('table').deleteRow(getRow(r));
   }   

 }
function updateRow(r){
 row = getRow(r);
 showAddInput(); 

 document.getElementById('btn_add').style="display:none" ;
 document.getElementById('btn_update').style="display:block-inline" ;
 insertInputFromQuery(queryInfoByRow(row));
  
}

          
    </script>

</head>

<body>
    <header>
        <hr/>
  
        <h1>订单信息管理系统</h1>
        <hr/>
    </header>
    <div>

        <span>
            <br><br><a href="/freshdata">订单管理</a><br><br><br>
            <a href="input9.jsp">订单信息录入</a><br><br><br>
            <a href="/history">历史订单</a><br><br><br>
            <a href="login9.jsp">退出登录</a><br>
        </span>
    </div>

<div class="first">

<div class="container">

    <header>
        <hr/>
  
        <h3 align="center" style="color: #9a9897;">订单信息管理</h3>
        <hr/>
    </header>


    <div align="center">
        <form class="form-inline" action="/inquire">

            <div class="form-group">
                <label>订单ID</label>
                <input type="telephone" name="id" class="form-control" >
            </div>

            <div class="form-group">
                <label>商品名字</label>
                <input type="text" name="name" class="form-control" >
            </div>

            

            &nbsp;  &nbsp;<button type="submit" class="btn btn-primary"<%-- onclick="window.location.href = '/inquire'" --%>>查询</button>
            
            &nbsp;  &nbsp; <button type="reset" class="btn btn-warning">重置</button>

        </form>
    </div>

    <div style="float: right; margin:5px">
        <a class="btn btn-primary" onclick="window.location.href = 'input9.jsp'">添加</a>
       <button class="btn btn-danger" id="delSelected" type="button" onclick=" deleteAll() " >批量删除</button>
    </div>
    

    <form id="form" method="post" >
        <div style="overflow-x: auto; overflow-y: auto; height: 300px; width:1100px;">
        <table border="1" class="table table-bordered table-hover">
            <tr class="success">
                <th><input type="checkbox" id="check" onclick="swapCheck()" />全选</th>
                <th>订单ID</th>
                <th>商品名字</th>
                <th>商品价格</th>
                <th>时间</th>
                <th>商品状态</th>
                <th>操作</th>
            </tr>

                <body id="tb">
                <%
                    try {


                    ArrayList<data> dataList =(ArrayList<data>)request.getAttribute("goodmessage");
                    for (data data :dataList)
                    {

                %>
                <tr id="1st">
                    <td><input type="checkbox" name="uid" id="uid"></td>
                    <td><%=data.getGoodsid()%></td>
                    <td><%=data.getGoodsname()%></td>
                    <td><%=data.getGoodsprice()%></td>
                    <td><%=data.getGoodstime()%></td>
                    <td><%=data.getGoodsstatus()%></td>
                    <td>
                        <button type="button" class="btn btn-primary" onclick="doModify(<%=data.getGoodsid()%>)">修改</button>
                        <button type="button" class="btn btn-danger" onclick="doDelete(<%=data.getGoodsid()%>")>删除</button>
                    </td>
                    <%
                        }
                        }catch (Exception e){
                        e.printStackTrace();
                        }
                    %>
                </tr>
          

                </body>

        </table>
        </div>
    </form>
   <div align="center">
<br><br><br><br>
            <ul class="pagination">
               <li>
                    <a href="#">
                        &laquo;
                    </a>
                </li>
                <li><a href="#">1</a></li>
                <li><a href="#">2</a></li>
                <li><a href="#">3</a></li>
                <li><a href="#">4</a></li>
                <li><a href="#">5</a></li>
                <li>
                    <a href="#">
                        &raquo;
                    </a>
                </li>
                <br>
                <br>
                <br>
              
                <button class="btn  btn-info" type="submit">首页</button>
                
                <button class="btn  btn-info" type="submit">上页</button>
                
                <button class="btn  btn-info" type="submit">下页</button>
                
                <button class="btn  btn-info" type="submit">尾页</button>
                <br>
                <a style="font-size: 16px;margin-left:20px" >
                    共35条记录,共5页
                </a>
            </ul>
    </div>
</div>

</div>

</body>

    <script>
         document.getElementById("check").onclick = function(){
        var checked = document.getElementById("check").checked;
        var checkson = document.getElementsByName("uid");
        if(checked){
            for(var i = 0; i < checkson.length ;i++){
                checkson[i].checked = true;
            }
        }else{
            for(var i = 0; i < checkson.length ;i++){
                checkson[i].checked = false;
            }
        }
    }

    </script>
    <script src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        //obj是点击行的this
        // function deleteTr(obj) {
        //     //通过this找到父级元素节点
        //     var tr = obj.parentNode.parentNode;
        //     //找到表格
        //     var tbody = tr.parentNode;
        //     //删除行
        //     tbody.removeChild(tr);
        //     //只剩行首时删除表格
        //     if (tbody.rows.length == 1) {
        //         tbody.parentNode.removeChild(tbody);
        //     }
        // }
    
    </script>
        
</html>